package com.atmaowei.service.impl;

import com.atmaowei.controller.request.BaseRequest;
import com.atmaowei.controller.request.DepartmentPageRequest;
import com.atmaowei.entity.Department;
import com.atmaowei.entity.Student;
import com.atmaowei.mapper.DepartmentMapper;
import com.atmaowei.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void save(Department department) {
        departmentMapper.save(department);
    }

    @Override
    public PageInfo<Department> page(BaseRequest baseRequest) {
        PageHelper.startPage(baseRequest.getPageNum(), baseRequest.getPageSize());
        List<Department> list = departmentMapper.page(baseRequest);
        PageInfo<Department> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void delete(String dno) {
        departmentMapper.delete(dno);
    }

    @Override
    public void update(Department department,String oldDname) {
        departmentMapper.update(department,oldDname);
    }

    @Override
    public Department getByDno(String dno) {
        return departmentMapper.getByDno(dno);
    }

    @Override
    public void deleteSelected(List<Department> departments) {
        for (Department department : departments) {
            departmentMapper.deleteSelected(department.getDno());
        }
    }
}
